<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="/layout/admin_template.xhtml">

    <ui:define name="body">
    	<h:form>
    		<h:panelGroup id="mask_id">
	    		<rich:panel id="ap_id">
	    			<f:facet name="header"></f:facet>
		    		<h:commandButton value="#{messages.back_msg}" action="discount" immediate="true"/>
		    		<rich:spacer width="10" />
		    		<a:commandButton value="#{messages.save_msg}" action="#{kDiscountManager.save()}" reRender="ap_id, messages"/>
		    		<br />
		    		<table>
		    			<tr>
		    				<td>
		    					<h:outputText value="#{messages.valid_from_msg}:" />
		    					<span class="m">*</span>
		    				</td>
		    				<td>
		    					<rich:calendar value="#{kDiscountManager.discount.validFrom}" required="true" showWeeksBar="false"/>
		    				</td>
		    			</tr>
		    			<tr>
		    				<td>
		    					<h:outputText value="#{messages.valid_to_msg}:" />
		    					<span class="m">*</span>
		    				</td>
		    				<td>
		    					<rich:calendar value="#{kDiscountManager.discount.validTo}" required="true" showWeeksBar="false"/>
		    				</td>
		    			</tr>
		    			<tr>
		    				<td>
		    					<h:outputText value="#{messages.active_msg}" />
		    				</td>
		    				<td>
		    					<h:selectBooleanCheckbox value="#{kDiscountManager.discount.active}" />
		    				</td>
		    			</tr>
		    			<tr>
		    				<td>
		    					<h:outputText value="#{messages.discount_msg}" />
		    					<span class="m">*</span>
		    				</td>
		    				<td>
		    					<h:inputText value="#{kDiscountManager.percent}" size="4" required="true" maxlength="4"/>&#160;%
		    				</td>
		    			</tr>
		    		</table>
		    		<br />
		    		<table>
		    			<tr>
		    				<td>
					    		<ui:include src="/pages/in/k_translate.xhtml" >
					    			<ui:param name="item" value="#{kDiscountManager.discount}" />
					    		</ui:include>
		    				</td>
		    			</tr>
		    		</table>
	    		</rich:panel>
	    		<h:panelGroup id="discount_items_id" rendered="#{kDiscountManager.discount.id gt 0}" >
		    		<a:commandButton value="#{messages.add_items_msg}" action="#{kDiscountManager.openItemPopup()}" 
		    			immediate="true" reRender="item_popup" />
		    		<rich:dataTable id="ai_table" value="#{kDiscountManager.items}" var="e">
		   				<rich:column>
		   					<f:facet name="header">
		   						<h:outputText value="#{messages.img_msg}" />
		   					</f:facet>
		   					<a href="/#{kInitParam.imgPath}/i_#{e.img.itemId}/#{e.img.name}" target="blank_">
		  						<img src="/#{kInitParam.imgPath}/i_#{e.img.itemId}/#{e.img.thumb}" width="50" height="50"/>
				   			</a>
		   				</rich:column>
		   				<rich:column>
		   					<f:facet name="header">
		   						<h:outputText value="#{messages.name_msg}" />
		   					</f:facet>
		  						<h:outputText value="#{e.item.getName(kUser.klang)}" />
		   				</rich:column>
		   				<rich:column>
		   					<f:facet name="header">
		   						<h:outputText value="#{messages.do_msg}" />
		   					</f:facet>
		   					<a:commandLink action="#{kDiscountManager.delete(e)}" value="#{messages.delete_msg}" immediate="true" reRender="discount_items_id"/>
		   				</rich:column>
		   				<f:facet name="footer">
		   					<rich:datascroller renderIfSinglePage="false"/>
		   				</f:facet>
		   			</rich:dataTable>
	    		</h:panelGroup>
    		</h:panelGroup>
    	</h:form>
    	<h:panelGroup id="item_popup">
    		<ui:include src="#{kDiscountManager.itemPopup ? '/pages/in/e_discount_item_popup.xhtml' : ''}" >
    			<ui:param name="reRenderIDS" value="discount_items_id, item_popup" />
    		</ui:include>
    	</h:panelGroup>
    </ui:define>
</ui:composition>
